package com.aimosheng.main.adapter;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;



import com.aimosheng.main.R;
import com.aimosheng.main.custom.videoplayerrecyclerview.VideoPlayAdapter;
import com.aimosheng.video.views.VideoPlayViewHolder;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;


public class MainVideoAdapter extends VideoPlayAdapter<MainVideoAdapter.MainVideoViewHolder> {


    private List<String> mVideos;

    public MainVideoAdapter() {
        this.mVideos = new ArrayList<>();
    }


    public void setData(List<String> videos){
        if(videos == null || videos.size() == 0)
            return;
        mVideos.clear();
        mVideos.addAll(videos);
        notifyDataSetChanged();
    }

    public void addData(List<String> videos){
        if(videos == null || videos.size() == 0)
            return;
        mVideos.addAll(videos);
        notifyDataSetChanged();
    }

    @androidx.annotation.NonNull
    @NotNull
    @Override
    public MainVideoViewHolder onCreateViewHolder(@androidx.annotation.NonNull @NotNull ViewGroup viewGroup, int i) {
        VideoPlayViewHolder mVideoPlayViewHolder = new VideoPlayViewHolder(viewGroup.getContext(), null);
        return new MainVideoViewHolder(mVideoPlayViewHolder.getContentView());
    }

    @Override
    public void onBindViewHolder(@androidx.annotation.NonNull @NotNull MainVideoViewHolder mainVideoViewHolder, int i) {
        mainVideoViewHolder.mName.setText(mVideos.get(i));
    }

    @Override
    public int getItemCount() {
        return mVideos.size();
    }

    @Override
    public void onPageSelected(int i, View view) {
        Log.d("video","onPageSelected index = "+i);
    }
    public static class MainVideoViewHolder extends RecyclerView.ViewHolder {
        private TextView mName;
        public MainVideoViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            mName = itemView.findViewById(R.id.tv_name);
        }
    }

}
